package com.orange.score.activity.repository;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;
import com.orange.score.activity.common.CommonFootballActivity;
import com.orange.score.app.ScoreApplication;
import com.orange.score.constants.LeagueType;
import com.orange.score.model.league.League;
import com.orange.score.model.league.LeagueManager;
import com.orange.score.model.repository.RepositoryManager;
import com.orange.score.service.RepositoryService;
import java.util.List;

public class RepositorySelectLeagueActivity extends CommonFootballActivity
{
  private static int DEFAULT_COLUMN;
  private static String TAG = RepositorySelectLeagueActivity.class.getName();
  Bundle bundle;
  private Button[] buttons;
  String countryId;
  String countryName;
  String keyword;
  LeagueManager leagueManager;
  TextView noResultTextView;
  RepositoryManager repositoryManager;
  private TableLayout tableLayout;
  TextView titleTextView;

  static
  {
    DEFAULT_COLUMN = 1;
  }

  private void buildTableLayout(List<League> paramList, int paramInt)
  {
    int i;
    int j;
    if (paramList == null);
    do
    {
      return;
      i = paramList.size();
      this.buttons = new Button[i];
      j = 0;
    }
    while (j >= i);
    TableRow localTableRow = new TableRow(this);
    TableRow.LayoutParams localLayoutParams = new TableRow.LayoutParams(-2, -2, 1F);
    localLayoutParams.width = 1;
    localLayoutParams.setMargins(5, 5, 5, 5);
    this.tableLayout.setLayoutParams(localLayoutParams);
    this.buttons[j] = new Button(this);
    if (j >= i)
    {
      this.buttons[j].setLayoutParams(localLayoutParams);
      localTableRow.addView(this.buttons[j]);
      this.buttons[j].setVisibility(4);
    }
    while (true)
    {
      while (true)
        ++j;
      League localLeague = (League)paramList.get(j);
      this.buttons[j].setGravity(16);
      this.buttons[j].setText(localLeague.getLeagueName());
      this.buttons[j].setLayoutParams(localLayoutParams);
      this.buttons[j].setSingleLine();
      this.buttons[j].setTextSize(14.0F);
      this.buttons[j].setBackgroundResource(2130837709);
      this.buttons[j].setHeight(33);
      localTableRow.addView(this.buttons[j]);
      this.tableLayout.addView(localTableRow);
      setLeagueSelectedButtonClickListener(this.buttons[j], localLeague);
    }
  }

  private LeagueManager getLeagueManager()
  {
    return getRepositoryService().getLeagueManager();
  }

  private RepositoryManager getRepositoryManager()
  {
    return getRepositoryService().getRepositoryManager();
  }

  private RepositoryService getRepositoryService()
  {
    return ((ScoreApplication)getApplication()).getRepositoryService();
  }

  private void setLeagueSelectedButtonClickListener(Button paramButton, League paramLeague)
  {
    paramButton.setOnLongClickListener(new View.OnLongClickListener(this, paramButton)
    {
      public boolean onLongClick()
      {
        this.val$button.setTextColor(-1);
        return false;
      }
    });
    paramButton.setOnClickListener(new View.OnClickListener(this, paramButton, paramLeague)
    {
      public void onClick()
      {
        this.val$button.setTextColor(-1);
        Intent localIntent = new Intent();
        if (this.val$league.getType() == LeagueType.LEAGUE.intValue())
          localIntent.setClass(this.this$0, LeagueScheduleActivity.class);
        while (true)
        {
          Bundle localBundle = new Bundle();
          localBundle.putString("leagueId", this.val$league.getLeagueId());
          localIntent.putExtras(localBundle);
          this.this$0.startActivity(localIntent);
          return;
          localIntent.setClass(this.this$0, CupScheduleActivity.class);
        }
      }
    });
  }

  private void showLeagueList()
  {
    if (this.keyword == null)
    {
      this.titleTextView.setText(this.countryName + "赛事资料库");
      List localList3 = this.leagueManager.filterLeagueByCountryId(this.countryId);
      if ((localList3 == null) || (localList3.size() <= 0))
        break label142;
      buildTableLayout(localList3, DEFAULT_COLUMN);
      this.noResultTextView.setVisibility(8);
    }
    while (true)
    {
      while (true)
      {
        return;
        this.titleTextView.setText("搜索结果");
        List localList1 = this.leagueManager.findAllLeagues();
        List localList2 = this.repositoryManager.getLeagueListByKey(localList1, this.keyword);
        if ((localList2 == null) || (localList2.size() <= 0))
          break;
        buildTableLayout(localList2, DEFAULT_COLUMN);
        this.noResultTextView.setVisibility(8);
      }
      label142: this.noResultTextView.setVisibility(0);
      this.tableLayout.setVisibility(8);
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903097);
    this.tableLayout = ((TableLayout)findViewById(2131558643));
    this.tableLayout.setStretchAllColumns(true);
    this.titleTextView = ((TextView)findViewById(2131558641));
    this.noResultTextView = ((TextView)findViewById(2131558642));
    this.bundle = getIntent().getExtras();
    this.countryId = this.bundle.getString("countryId");
    this.countryName = this.bundle.getString("countryName");
    this.keyword = this.bundle.getString("key");
    this.leagueManager = getLeagueManager();
    this.repositoryManager = getRepositoryManager();
    showLeagueList();
  }

  public void onRefresh()
  {
  }

  protected void onResume()
  {
    int i;
    super.onResume();
    if ((this.buttons != null) && (this.buttons.length > 0))
      i = 0;
    while (true)
    {
      if (i >= this.buttons.length)
        return;
      if (this.buttons[i] != null)
        this.buttons[i].setTextColor(-16777216);
      ++i;
    }
  }
}